package ypmits.videoplayer.business {
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.text.TextField;

	/**
	 * @author ypmits
	 */
	public class Validator {

		
		/**
		 * Returns an array like : [ true, ["error1", "error2"] ]
		 * the first value is a boolean to indicate if the validation passed,
		 * the second part is an array with the error-messages. 
		 */
		public static function validateControlSprite( sprite : DisplayObject ) : Array {
			var ok : Boolean = true;
			var errorstrings : Array = [];

			if( !sprite['title'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'controlSprite.title' graphic" );
			}
			if( !sprite['title'] is TextField ) {
				ok = false;
				errorstrings.push( "ERROR! 'title' should be a TextField" ); 
			}
			if( !sprite['timetogo'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'controlSprite.timetogo' graphic" ); 
			}
			if( !sprite['timetogo'] is TextField ) {
				ok = false;
				errorstrings.push( "ERROR! 'timetogo' should be a TextField" ); 
			}
			if( !sprite['timepast'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'controlSprite.timepast' graphic" ); 
			}
			if( !sprite['timepast'] is TextField ) {
				ok = false;
				errorstrings.push( "ERROR! 'timepast' should be a TextField" ); 
			}
			if( !sprite['playpausebutton'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'controlSprite.playpausebutton'" ); 
			}
			if( !sprite['playpausebutton'] is MovieClip ) {
				ok = false;
				errorstrings.push( "ERROR! 'playpausebutton' should be a MovieClip" ); 
			}
			if( MovieClip( sprite['playpausebutton'] ).totalFrames != 2 ) {
				ok = false;
				errorstrings.push( "ERROR! 'playpausebutton' should have 2 frames" ); 
			}
			if( !sprite['controlbar'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'There's no 'controlSprite.playpausebutton'" ); 
			}
			if( !sprite['controlbar']['playhead'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'There's no 'controlSprite.controlbar.playhead' graphic" ); 
			}
			if( !sprite['controlbar']['pasttimebar'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'There's no 'controlSprite.controlbar.pasttime' graphic" ); 
			}
			if( !sprite['controlbar']['bufferbar'] ) {
				ok = false;
				errorstrings.push( "ERROR! There's no 'There's no 'controlSprite.controlbar.bufferbar' graphic" ); 
			}
			
			return [ ok, errorstrings ];
		}
	}
}
